package com.project.poetry.common.job.config;

import com.project.poetry.common.job.QuartzUtil;
import com.project.poetry.common.util.CommonUtil;
import com.project.poetry.service.entity.po.job.JobPO;
import com.project.poetry.service.mapper.JobMapper;
import org.quartz.SchedulerException;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author mengxj
 */
@Component
public class QuartzInit implements ApplicationRunner {

    @Resource
    private JobMapper jobMapper;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<JobPO> jobs = this.jobMapper.selectList(null);
        if(CommonUtil.isEmpty(jobs)){
            return;
        }
        for(JobPO job: jobs){
            QuartzUtil.initScheduler(job);
        }
    }
}
